<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<form action="j1.html" method="get">
			用户名：<input type="text" name="username" id="username" value="" />
			<br/>
			<!--案例视频03-->
			身份证：
			<input type="text" name="sid" onblur="return check(this)" />
			<input type="submit" value="提交"/>
		</form>
		
		<script type="text/javascript">
			function check(sid){
				if(sid.value.length!=18){
					alert("18位");
					return false;
				}
				if(!checkNum(sid.value)){
					alert("数字,X,x");
					return false;
				}
				alert("提取年月日");
				var val = sid.value;
				alert(val);
				var year = val.substr(6,4);
				var month = val.substr(10,2);
				var day = val.substr(12,2);
				alert(year+"-"+month+"-"+day);
				return true;
			}
			
			
			function checkNum(val){
				var flag = true;
				//判断前17位是不是数字
				for(var i = 0;i<val.length-1;i++){
					if(!(val[i]>=0 && val[i]<=9)){
						flag = false;
						break;
					}
				}
				//判断第18位是不是数字，X，x
				if(flag){
					if(!(val[i]>=0&&val[i]<=9||val[i]=="x"||val[i]=="X")){
						flag = false;
					}
				}
				return flag;
			}
		</script>
	</body>
</html>
